package data;


import anaydis.sort.data.DataSetGenerator;
import org.jetbrains.annotations.NotNull;

import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

public class StringDataSetGenerator implements DataSetGenerator {


    @NotNull
    public List<String> createAscending(int i) {
        return null;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @NotNull
    public List<String> createDescending(int i) {
        return null;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @NotNull
    public List<String> createRandom(int i) {
        return null;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @NotNull
    public Comparator<String> getComparator() {
        return new Comparator<String>() {
            public int compare(String i, String j) {
                return i.compareTo(j);
            }
        };
    }


    public List<String> createFromFile(String fileName, int n) {
        List<String> list = new ArrayList<String>();
        try {
            FileReader fr = new FileReader(fileName);
            int c = fr.read();
            int i = 0;
            String w = "";
            while (c != -1 && i < n) {
                if (isLetter(c)) {
                    w += (char) c;
                } else {
                    if (w.length() > 0) {
                        w += "aa";
                        list.add(w);
                        i++;
                        w = "";
                    }
                }
                c = fr.read();
            }
        } catch (IOException e) {
            System.out.println(e.getMessage());
        }
        return list;
    }

    private boolean isLetter(int i) {
        return ((i > 64) && (i < 91)) || ((i >= 97) && (i <= 122));
    }
}
